package com.huizhonglm.diap.ui.wallet;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.huizhonglm.diap.R;
import com.huizhonglm.diap.api.model.wallet.BankCardInfo;

import java.util.List;

/**
 * 描述当前类的作用
 *
 * @author LiXiaoLong
 * @version 1.0
 * @since 2016-03-29 11:44
 */
public class WithdrawAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private List<BankCardInfo> data;

    public WithdrawAdapter(LayoutInflater inflater, List<BankCardInfo> data) {
        this.inflater = inflater;
        this.data = data;
    }

    public void setData(List<BankCardInfo> data){
        this.data = data;
    }

    @Override
    public int getCount() {
        return data != null ? data.size() : 0;
    }

    @Override
    public BankCardInfo getItem(int position) {
        return data != null ? data.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        ViewHolder holder;
        if (view == null) {
            holder = new ViewHolder();
            view = inflater.inflate(R.layout.item_withdraw_card, parent, false);
            holder.nameTxt = (TextView) view.findViewById(R.id.bank_card_txt);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        BankCardInfo info = getItem(position);
        String no = info.getCardNo().substring(info.getCardNo().length() - 4);
        String name = info.getBankName() + "（尾号"+ no + "）";
        holder.nameTxt.setText(name);
        return view;
    }

    private class ViewHolder {
        private TextView nameTxt;
    }
}
